package com.ruoyi.psi.inventory.transfer.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.inventory.transfer.domain.InventoryTransfer;
import com.ruoyi.psi.inventory.transfer.service.IInventoryTransferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 产品库存调拨
 */
@RestController
@RequestMapping("/psi/inventory/transfer")
@Api(value = "产品库存调拨模块", tags = "产品库存调拨接口")
public class InventoryTransferController extends BaseController {
    @Autowired
    private IInventoryTransferService inventoryTransferService;



    /**
     * 获取仓库调拨
     * @param inventoryTransfer
     * @return
     */
    @ApiOperationSupport(includeParameters = {"InventoryTransfer.inventoryTransferId", "InventoryTransfer.staffId", "InventoryTransfer.createTime"})
    @ApiOperation(value = "获取仓库调拨",notes = "查询所有仓库调拨信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InventoryTransfer inventoryTransfer) {
        startPage();
        List<InventoryTransfer> inventoryTransfers = inventoryTransferService.selectInventoryTransferList(inventoryTransfer);
        return getDataTable(inventoryTransfers);
    }

    /**
     * 导出仓库调拨
     *
     * @param inventoryTransfer
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody InventoryTransfer inventoryTransfer) {
        List<InventoryTransfer> inventoryTransfers = inventoryTransferService.selectInventoryTransferList(inventoryTransfer);
        ExcelUtil<InventoryTransfer> util = new ExcelUtil<InventoryTransfer>(InventoryTransfer.class);
        return util.exportExcel(inventoryTransfers, "仓库调拨单数据");
    }

    /**
     * 新增仓库调拨
     * @param inventoryTransfer 仓库调拨单据
     * @return
     */
    @ApiOperation(value = "新增仓库调拨", notes = "新增仓库调拨")
    @ApiImplicitParam(name = "inventoryTransfer", value = "新增仓库调拨", dataType = "InventoryTransfer")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody InventoryTransfer inventoryTransfer) {
        try {
            inventoryTransferService.insertInventoryTransfer(inventoryTransfer);
            return AjaxResult.success("新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增失败");
        }
    }

    /**
     *
     * 更新仓库调拨
     * @param inventoryTransfer 仓库调拨单据
     * @return
     */
    @ApiOperation(value = "更新仓库调拨", notes = "更新仓库调拨")
    @ApiImplicitParam(name = "inventoryTransfer", value = "更新仓库调拨", dataType = "InventoryTransfer")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody InventoryTransfer inventoryTransfer) {
        try {
            inventoryTransferService.updateInventoryTransfer(inventoryTransfer);
            return AjaxResult.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除仓库调拨
     * 仅修改删除标志位
     *
     * @param inventoryTransfer 仓库调拨单据
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody InventoryTransfer inventoryTransfer) {

        return toAjax(inventoryTransferService.updateInventoryTransferDeleteFlag(inventoryTransfer));
    }




}
